using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NoteLineConnector : MonoBehaviour
{
    public NoteObject noteObjectA;
    public NoteObject noteObjectB;
    public Transform noteA;
    public Transform noteB;
    private LineRenderer lr;
    

    void Awake()
    {
        lr = GetComponent<LineRenderer>();
        lr.positionCount = 2;
        lr.startWidth = 0.05f;
        lr.endWidth = 0.05f;
    }

    void LateUpdate()
    {
        if (noteA != null && noteB != null)
        {
            lr.enabled = true;
            lr.SetPosition(0, noteA.position);
            lr.SetPosition(1, noteB.position);
        }
        else
        {
            lr.enabled = false;
        }
    }

    public void Initialize(NoteObject a, NoteObject b)
    {
        noteObjectA = a;
        noteObjectB = b;
        noteA = a.transform;
        noteB = b.transform;
        a.connector = this;
        b.connector = this;
    }

    public void DestoryLine(NoteObject note)
    {
        if (noteObjectA == note || noteObjectB == note) 
        {
            noteA = null;
            noteB = null;
            this.lr.enabled = false;
            Destroy(gameObject);
        }
    }
}
